<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>汉中旅游 - 探索千年古城</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="css/style.css">
    <meta name="description" content="汉中旅游官方网站，提供汉中景点、美食、住宿、交通等全方位旅游信息，让您的汉中之旅更加便捷、愉快。">
    <link rel="icon" href="img/favicon.ico" type="image/x-icon">
</head>
<body>
    <!-- 页面加载动画 -->
    <div class="page-loader">
        <div class="loader"></div>
    </div>

    <!-- 用户小部件 -->
    <div class="user-widget">
        <a href="login.html" id="login-link" class="btn btn-login">登录/注册</a>
        <div id="user-profile" style="display: none;">
            <img src="img/attractions/touxiang.jpg" alt="User Avatar" class="avatar">
            <span id="username-display"></span>
            <a href="#" id="logout-link" title="退出登录"><i class="fas fa-sign-out-alt"></i></a>
        </div>
    </div>

    <!-- 导航栏 -->
    <nav id="main-navbar">
        <div class="nav-container container">
            <div class="nav-logo">
                <a href="index.html">
                    <img src="img/attractions/logo.jpg" alt="汉中旅游" class="nav-logo-img">
                    <h2 class="nav-title">汉中旅游</h2>
                </a>
            </div>
            <ul class="main-nav">
                <li><a href="index.html" class="active">首页</a></li>
                <li><a href="jingdian.html">景点介绍</a></li>
                <li><a href="luxian.html">旅游线路</a></li>
                <li><a href="gonglue.html">旅游攻略</a></li>
                <li><a href="meishi.html">美食推荐</a></li>
                <li><a href="wenhua.html">汉文化活动</a></li>
                <li><a href="contact.html">联系我们</a></li>
                <li><a href="faq.html">常见问题</a></li>
            </ul>
            <!-- 用户操作区域已被移到独立的 user-widget 中 -->
        </div>
    </nav>

    <!-- 主要内容 -->
    <main>
        <!-- 轮播图 -->
        <section class="carousel">
            <div class="carousel-container">
                <div class="carousel-slide">
                    <img src="img/attractions/hanzhong.jpg" alt="汉中风光">
                    <div class="carousel-caption">
                        <h2>探索千年古城</h2>
                        <p>感受汉中深厚的历史文化底蕴</p>
                    </div>
                </div>
                <div class="carousel-slide">
                    <img src="img/attractions/wuhouci.jpg" alt="武侯祠">
                    <div class="carousel-caption">
                        <h2>三国文化之旅</h2>
                        <p>追寻诸葛亮的足迹</p>
                    </div>
                </div>
                <div class="carousel-slide">
                    <img src="img/attractions/youcaihua.jpg" alt="油菜花海">
                    <div class="carousel-caption">
                        <h2>春季油菜花海</h2>
                        <p>金黄色的海洋，醉人的美景</p>
                    </div>
                </div>
                <div class="carousel-slide">
                    <img src="img/attractions/hanzhongneishi.jpg" alt="汉中美食">
                    <div class="carousel-caption">
                        <h2>品味汉中美食</h2>
                        <p>舌尖上的汉中，独特的味觉体验</p>
                    </div>
                </div>
                <div class="carousel-slide">
                    <img src="img/attractions/zibaishan.jpg" alt="紫柏山国家森林公园">
                    <div class="carousel-caption">
                        <h2>紫柏山国家森林公园</h2>
                        <p>天然氧吧，森林覆盖率高达95%</p>
                    </div>
                </div>
            </div>
            <div class="carousel-controls">
                <button class="carousel-control carousel-prev" aria-label="上一张"><i class="fas fa-chevron-left"></i></button>
                <button class="carousel-control carousel-next" aria-label="下一张"><i class="fas fa-chevron-right"></i></button>
            </div>
            <div class="carousel-indicators">
                <span class="carousel-indicator active"></span>
                <span class="carousel-indicator"></span>
                <span class="carousel-indicator"></span>
                <span class="carousel-indicator"></span>
                <span class="carousel-indicator"></span>
            </div>
        </section>

        <!-- 快速导航 -->
        <section class="container">
            <div class="quick-nav">
                <a href="jingdian.html" class="quick-nav-item">
                    <div class="quick-nav-icon">
                        <i class="fas fa-mountain"></i>
                    </div>
                    <span>景点介绍</span>
                </a>
                <a href="luxian.html" class="quick-nav-item">
                    <div class="quick-nav-icon">
                        <i class="fas fa-route"></i>
                    </div>
                    <span>旅游线路</span>
                </a>
                <a href="gonglue.html" class="quick-nav-item">
                    <div class="quick-nav-icon">
                        <i class="fas fa-map-marked-alt"></i>
                    </div>
                    <span>旅游攻略</span>
                </a>
                <a href="meishi.html" class="quick-nav-item">
                    <div class="quick-nav-icon">
                        <i class="fas fa-utensils"></i>
                    </div>
                    <span>美食推荐</span>
                </a>
                <a href="wenhua.html" class="quick-nav-item">
                    <div class="quick-nav-icon">
                        <i class="fas fa-theater-masks"></i>
                    </div>
                    <span>汉文化活动</span>
                </a>
            </div>
        </section>

        <!-- 汉中简介 -->
        <section class="container section-padding">
            <div class="intro-container">
                <div class="intro-content fade-in">
                    <h2 class="section-title">汉中简介</h2>
                    <p>汉中，古称南郑，位于陕西省南部，是一座有着3000多年历史的文化古城。这里是汉族和汉文化的重要发祥地，也是三国文化的重要遗址。</p>
                    <p>汉中地处秦岭南麓，汉水中游，气候温和，四季分明，自然风光秀美，人文景观丰富。这里有雄伟的秦岭山脉，清澈的汉江水系，还有众多历史古迹和文化遗产。</p>
                    <p>作为"汉家发祥地，三国文化城"，汉中拥有武侯墓、定军山、南湖等著名景点，以及丰富的非物质文化遗产，如汉调桄桄子、汉中皮影戏等。此外，汉中还以其独特的美食文化吸引着众多游客。</p>
                    <div class="intro-buttons">
                        <a href="jingdian.html" class="btn">探索景点</a>
                        <a href="gonglue.html" class="btn btn-outline">旅游攻略</a>
                    </div>
                </div>
                <div class="intro-image fade-in hover-zoom">
                    <img src="img/attractions/hanzhongquanjing.jpg" alt="汉中全景">
                </div>
            </div>
        </section>

        <!-- 热门景点 -->
        <section class="container section-padding">
            <h2 class="section-title">热门景点</h2>
            <div id="hot-attractions">
                <div class="loading-placeholder">
                    <i class="fas fa-spinner fa-spin"></i>
                    <p>正在加载景点信息...</p>
                </div>
            </div>
            <div class="text-center" style="margin-top: 20px;">
                <a href="jingdian.html" class="btn btn-large">查看更多景点</a>
            </div>
        </section>

        <!-- 最新活动 -->
        <section class="latest-events">
            <div class="container section-padding">
                <h2 class="section-title">最新活动</h2>
                <div class="events-grid" id="upcoming-activities">
                    <div class="loading-placeholder">
                        <i class="fas fa-spinner fa-spin"></i>
                        <p>正在加载活动信息...</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- 旅游资讯 -->
        <section class="container section-padding">
            <h2 class="section-title">旅游资讯</h2>
            <div class="news-grid">
                <div class="news-item slide-in-left">
                    <div class="news-image hover-zoom">
                        <img src="img/attractions/gaotie.jpg" alt="高铁资讯">
                    </div>
                    <div class="news-content">
                        <span class="news-date">2023-12-15</span>
                        <h3>西安至汉中高铁增开班次</h3>
                        <p>为满足旅客出行需求，西安至汉中高铁线路将从2024年1月起增开班次，每天往返班次将达到20对，进一步方便游客出行。</p>
                        <a href="#" class="news-link">阅读全文 <i class="fas fa-arrow-right"></i></a>
                    </div>
                </div>
                <div class="news-item fade-in">
                    <div class="news-image hover-zoom">
                        <img src="img/attractions/jingqu.jpg" alt="景区优惠">
                    </div>
                    <div class="news-content">
                        <span class="news-date">2023-12-10</span>
                        <h3>汉中推出冬季旅游优惠套餐</h3>
                        <p>为促进冬季旅游，汉中市文化和旅游局联合多家景区推出冬季旅游优惠套餐，包含景点门票、住宿和特色体验活动，优惠力度达30%。</p>
                        <a href="#" class="news-link">阅读全文 <i class="fas fa-arrow-right"></i></a>
                    </div>
                </div>
                <div class="news-item slide-in-right">
                    <div class="news-image hover-zoom">
                        <img src="img/attractions/shimenzhandao.jpg" alt="石门栈道">
                    </div>
                    <div class="news-content">
                        <span class="news-date">2023-12-01</span>
                        <h3>石门栈道修缮工程完成，重新开放</h3>
                        <p>经过半年的修缮工程，汉中石门栈道已于近日重新对外开放。此次修缮保留了栈道的历史风貌，同时提升了安全性和游览体验，为游客提供更好的旅游环境。</p>
                        <a href="jingdian.html#shimenzhandao" class="news-link">阅读全文 <i class="fas fa-arrow-right"></i></a>
                    </div>
                </div>
            </div>
        </section>

        <!-- 旅游小贴士 -->
        <section class="tips-section">
            <div class="container section-padding">
                <h2 class="section-title">旅游小贴士</h2>
                <div class="tips-container">
                    <div class="tip-box fade-in">
                        <div class="tip-icon">
                            <i class="fas fa-calendar-alt"></i>
                        </div>
                        <h3>最佳旅游时间</h3>
                        <p>汉中的最佳旅游时间是春季（3-5月）和秋季（9-11月），此时气候宜人，风景优美。春季可以欣赏油菜花海，秋季可以观赏紫柏山和龙头山的红叶。</p>
                    </div>
                    <div class="tip-box fade-in">
                        <div class="tip-icon">
                            <i class="fas fa-plane"></i>
                        </div>
                        <h3>交通出行</h3>
                        <p>汉中有机场、高铁和高速公路，交通便利。市内可乘坐公交车、出租车或共享单车出行，景点之间可选择包车或乘坐班车。</p>
                    </div>
                    <div class="tip-box fade-in">
                        <div class="tip-icon">
                            <i class="fas fa-utensils"></i>
                        </div>
                        <h3>特色美食</h3>
                        <p>来汉中一定要品尝汉中面皮、汉中炕炉羊肉、汉中豆腐等特色美食，这些都是当地最具代表性的传统美食。</p>
                    </div>
                    <div class="tip-box fade-in">
                        <div class="tip-icon">
                            <i class="fas fa-shopping-bag"></i>
                        </div>
                        <h3>特产购物</h3>
                        <p>汉中的特产有汉中仙毫茶、汉中锅巴、木雕、剪纸等，这些都是馈赠亲友的佳品，可在市区特产店或景区购买。</p>
                    </div>
                </div>
                <div class="text-center">
                    <a href="gonglue.html" class="btn">查看详细攻略</a>
                </div>
            </div>
        </section>

        <!-- 用户评价 -->
        <section class="container section-padding">
            <h2 class="section-title">游客评价</h2>
            <div class="testimonials-container">
                <div class="testimonial fade-in">
                    <div class="testimonial-content">
                        <p>"汉中是一座充满历史底蕴的城市，武侯墓和定军山让我深刻感受到了三国文化的魅力。当地人热情好客，美食也很赞，特别是汉中面皮，太好吃了！"</p>
                    </div>
                    <div class="testimonial-author">
                        <img src="img/attractions/touxiang.jpg" alt="用户头像">
                        <div class="author-info">
                            <h4>胖怡</h4>
                            <p>来自北京</p>
                            <div class="rating">
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="testimonial fade-in">
                    <div class="testimonial-content">
                        <p>"春天的汉中太美了！漫山遍野的油菜花，金黄一片，美不胜收。南湖公园的樱花也很漂亮，是拍照的好地方。住宿和交通都很方便，推荐大家来玩！"</p>
                    </div>
                    <div class="testimonial-author">
                        <img src="img/attractions/touxiang2.jpg" alt="用户头像">
                        <div class="author-info">
                            <h4>胖晖</h4>
                            <p>来自上海</p>
                            <div class="rating">
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star-half-alt"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="testimonial fade-in">
                    <div class="testimonial-content">
                        <p>"作为一个历史爱好者，我对汉中的历史古迹非常着迷。武侯祠、定军山、古城墙等景点都保存得很好。此外，汉中的自然风光也很美，天台山的风景令人难忘。"</p>
                    </div>
                    <div class="testimonial-author">
                        <img src="img/attractions/buer.jpg" alt="用户头像">
                        <div class="author-info">
                            <h4>布二</h4>
                            <p>来自成都</p>
                            <div class="rating">
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 订阅区域 -->
        <section class="subscribe-section">
            <div class="container section-padding">
                <div class="subscribe-container">
                    <div class="subscribe-content">
                        <h2>订阅我们的旅游资讯</h2>
                        <p>获取最新的汉中旅游信息、活动预告和独家优惠</p>
                    </div>
                    <form class="subscribe-form" data-validate="true">
                        <input type="email" placeholder="请输入您的邮箱地址" required>
                        <button type="submit" class="btn">订阅</button>
                    </form>
                </div>
            </div>
        </section>
    </main>

    <!-- 页脚 -->
    <footer>
        <div class="container">
            <div class="footer-content">
                <div class="footer-section">
                    <h3>关于我们</h3>
                    <p>汉中旅游网致力于为游客提供最全面的汉中旅游信息，让您的汉中之行更加便捷、愉快。</p>
                    <div class="social-links">
                        <a href="#" aria-label="微博"><i class="fab fa-weibo"></i></a>
                        <a href="#" aria-label="微信"><i class="fab fa-weixin"></i></a>
                        <a href="#" aria-label="QQ"><i class="fab fa-qq"></i></a>
                    </div>
                </div>
                <div class="footer-section">
                    <h3>快速链接</h3>
                    <ul>
                        <li><a href="index.html">首页</a></li>
                        <li><a href="jingdian.html">景点介绍</a></li>
                        <li><a href="luxian.html">旅游线路</a></li>
                        <li><a href="gonglue.html">旅游攻略</a></li>
                        <li><a href="contact.html">联系我们</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>热门景点</h3>
                    <ul>
                        <li><a href="jingdian.html#wuhoumu">武侯墓</a></li>
                        <li><a href="jingdian.html#nanhu">南湖</a></li>
                        <li><a href="jingdian.html#dingjunshan">定军山</a></li>
                        <li><a href="jingdian.html#guchengqiang">古城墙</a></li>
                        <li><a href="jingdian.html#qingmuchuan">青木川古镇</a></li>
                        <li><a href="jingdian.html#shimenzhandao">石门栈道</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>联系方式</h3>
                    <p><i class="fas fa-map-marker-alt"></i> 地址：陕西省汉中市</p>
                    <p><i class="fas fa-phone"></i> 电话：18165245563</p>
                    <p><i class="fas fa-envelope"></i> 邮箱：1959847182@qq.com</p>
                </div>
            </div>
        </div>
        <div class="footer-bottom">
            <div class="container">
                <p>&copy; 2024 汉中旅游网 版权所有</p>
            </div>
        </div>
    </footer>

    <script src="js/api.js"></script>
    <script src="js/script.js"></script>
    <script>
        // 页面加载完成后初始化API数据
        document.addEventListener('DOMContentLoaded', async function() {
            try {
                // 加载热门景点数据
                console.log('开始加载热门景点数据...');
                const attractions = await TravelAPI.getAllAttractions();
                console.log('获取到景点数据:', attractions);
                
                if (attractions && attractions.length > 0) {
                    const hotAttractions = attractions.slice(0, 3);
                    DataRenderer.renderAttractions(hotAttractions, 'hot-attractions');
                } else {
                    document.getElementById('hot-attractions').innerHTML = 
                        '<div class="api-error"><i class="fas fa-exclamation-triangle"></i>暂无景点数据</div>';
                }
                
                // 加载即将举行的活动数据
                console.log('开始加载活动数据...');
                const activities = await TravelAPI.getAllCulturalActivitiesV1();
                console.log('获取到活动数据:', activities);
                
                if (activities && activities.length > 0) {
                    const upcomingActivities = activities.slice(0, 3);
                    DataRenderer.renderHomePageActivities(upcomingActivities, 'upcoming-activities');
                } else {
                    document.getElementById('upcoming-activities').innerHTML = 
                        '<div class="api-error"><i class="fas fa-info-circle"></i>暂无活动数据</div>';
                }

                // 关键修复：在动态内容插入后，手动重新触发一次滚动动画扫描
                if (typeof handleScrollAnimation === 'function') {
                    console.log('重新触发滚动动画扫描...');
                    handleScrollAnimation();
                }
                
            } catch (error) {
                console.error('加载数据时发生错误:', error);
                
                const hotAttractionsContainer = document.getElementById('hot-attractions');
                if (hotAttractionsContainer) {
                    hotAttractionsContainer.innerHTML = 
                        '<div class="api-error"><i class="fas fa-exclamation-triangle"></i>加载景点数据失败</div>';
                }
                
                const activitiesContainer = document.getElementById('upcoming-activities');
                if (activitiesContainer) {
                    activitiesContainer.innerHTML = 
                        '<div class="api-error"><i class="fas fa-exclamation-triangle"></i>加载活动数据失败</div>';
                }
            }
        });

        document.addEventListener('DOMContentLoaded', function() {
            const token = localStorage.getItem('jwt_token');
            const loginLink = document.getElementById('login-link');
            const userProfile = document.getElementById('user-profile');
            const usernameDisplay = document.getElementById('username-display');
            const logoutLink = document.getElementById('logout-link');

            if (token) {
                // User is logged in
                loginLink.style.display = 'none';
                userProfile.style.display = 'flex';

                try {
                    // Decode JWT to get username
                    const payload = JSON.parse(atob(token.split('.')[1]));
                    usernameDisplay.textContent = payload.sub; // 'sub' is standard for subject/username
                } catch (e) {
                    console.error('Failed to decode JWT:', e);
                    usernameDisplay.textContent = '用户';
                }

            } else {
                // User is not logged in
                loginLink.style.display = 'block';
                userProfile.style.display = 'none';
            }

            logoutLink.addEventListener('click', function(e) {
                e.preventDefault();
                localStorage.removeItem('jwt_token');
                window.location.reload(); // Refresh the page to update state
            });
        });
    </script>
</body>
</html>
